/**
 * 获取所有叶子节点的id
 * @param data
 * @returns
 */
export const getAllLeafIds = (data: any[]): string[] => {
  const result: string[] = [];
  function traverse(node: any) {
    if (!node.children || node.children.length === 0) {
      result.push(node.id);
    } else {
      node.children.forEach((child) => traverse(child));
    }
  }

  data.forEach((item) => traverse(item));

  return result;
};

/**
 * 获取所有节点的id
 */
export const getAllNodeIds = (data: any[]): string[] => {
  const result: string[] = [];

  function traverse(node: any) {
    result.push(node.id);
    if (node.children && node.children.length > 0) {
      node.children.forEach((child) => traverse(child));
    }
  }

  data.forEach((item) => traverse(item));

  return result;
};
